package com.whr.service;

import com.whr.bean.Role;
import com.whr.bean.Times;
import com.whr.dao.ProblemMapper;
import com.whr.dao.RoleMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional
@Service("roleService")
public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleMapper roleMapper;
    @Resource
    private ProblemMapper problemMapper;

    @Override
    public List<Role> findAll() {
        return roleMapper.selectAll();
    }

    @Override
    public void saveRole(Role role) {
        role.setOstate("启用");
        role.setOflag(role.getOname());
        roleMapper.insert(role);
    }

    @Override
    public void stop(Integer[] checks) {
        roleMapper.stopRole(checks);
    }

    @Override
    public void start(Integer[] checks) {
        roleMapper.startRole(checks);
    }

    @Override
    public Role findById(Integer checks) {
        return roleMapper.selectByPrimaryKey(checks);
    }

    @Override
    public void updateRole(Role role, String rname) {
        roleMapper.updateByPrimaryKey(role);
        problemMapper.updateProbRol(role.getOname(),rname);
    }

    @Override
    public void delRole(Integer[] checks) {
        roleMapper.delRole(checks);
    }

    @Override
    public List<String> selRoleName() {
        return roleMapper.selRoleName();
    }
    public List<String> selRoleNick() {
        return roleMapper.selRoleNick();
    }

    @Override
    public void updatePath(Integer oid,String path) {
        roleMapper.updatePath(oid,path);
    }

    @Override
    public Times findTimes() {
        return roleMapper.findTimes();
    }

    @Override
    public void upprob(Integer prob) {
        roleMapper.upprob(prob);
    }

    @Override
    public void uppass(Integer pass) {
        roleMapper.uppass(pass);
    }

    @Override
    public String getPathByRole(String role) {
        return roleMapper.getPathByRole(role);
    }

    @Override
    public String findFlag(String role) {
        return roleMapper.findFlag(role);
    }


}
